package SOEN_Phase_3;

import junit.framework.TestCase;
import junit.framework.Assert;

import java.util.ArrayList;

public class PersonTableTest extends TestCase {
	
	public void testInitFromTaskTable() {
		TaskTable tt = new TaskTable("tasks.xml");
		PersonTable pt = new PersonTable(tt);
		
		pt.initFromTaskTable(tt);
			
		
	}

	public void testWriteToXML() {
		TaskTable tt = new TaskTable("tasks.xml");
		PersonTable pt = new PersonTable(tt);
		
		pt.writeToXML("outputTEST1.xml");
	}

	public void testPrintPersonsTable() {
		TaskTable tt = new TaskTable("tasks.xml");
		PersonTable pt = new PersonTable(tt);
		
		pt.printPersonsTable(null, "outputTEST3.txt");
	}

	public void testGetPersonByID() {
	
		TaskTable tt = new TaskTable("tasks.xml");
		PersonTable pt = new PersonTable(tt);
		Person act = pt.getPersonByID(0);
		Person exp = new Person("Samantha", 0);	
		
		assertTrue(exp.getID() == act.getID());
	}

	public void testAssignTask() {
		TaskTable tt = new TaskTable("tasks.xml");
		PersonTable pt = new PersonTable(tt);
		ArrayList<Task> a = new ArrayList<Task>();
		ArrayList<Integer> b = new ArrayList<Integer>();
		Task g = new Task(12,5,"title","name", 5, 0, false, a, b);
		
		pt.assignTask(0, g);
		
		Person test = pt.getPersonByID(0);
		
		ArrayList<Task> k = test.getTasks();
		
		Task gPrime = k.get(k.size()-1);
		
		assertTrue(g == gPrime);
		
		
	}

	public void testTryRegisterPerson() {
		TaskTable tt = new TaskTable("tasks.xml");
		PersonTable pt = new PersonTable(tt);
		
		boolean test1 = !pt.tryRegisterPerson("John", 0);
		
		assertTrue("Test 1 failed", test1);
		
		boolean test2 = pt.tryRegisterPerson("John", 4);
		
		assertTrue("Test 2 failed", test2);
		
		Person t = pt.getPersonByID(4);
		
		assertTrue("Did not register",t.getName().equalsIgnoreCase("John"));
		
	}

}
